Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Implement Stats data capture feature
Browse files Browse the repository at this point in the history
  • Loading branch information
uBlockAdmin committed Apr 11, 2018
1 parent dfea165 commit 76b89c0
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 2 deletions.
4 changes: 2 additions & 2 deletions platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 2,

"name": "uBlock",
"version": "0.9.5.3-beta.2",

"version": "0.9.5.4",
"default_locale": "en",
"description": "__MSG_extShortDesc__",
"icons": {
Expand Down
1 change: 1 addition & 0 deletions src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
<script src="js/contextmenu.js"></script>
<script src="js/mirrors.js"></script>
<script src="js/start.js"></script>
<script src="js/stats.js"></script>
</body>
</html>
185 changes: 185 additions & 0 deletions src/js/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@

µBlock.stats = (function () {

var µb = µBlock;

var reOS = /(CrOS\ \w+|Windows\ NT|Mac\ OS\ X|Linux)\ ([\d\._]+)?/;

var matches = reOS.exec(navigator.userAgent);

var operatingSystem = (matches || [])[1] || "Unknown";

var operatingSystemVersion = (matches || [])[2] || "Unknown";

var reBW = /(MSIE|Trident|(?!Gecko.+)Firefox|(?!AppleWebKit.+Chrome.+)Safari(?!.+Edge)|(?!AppleWebKit.+)Chrome(?!.+Edge)|(?!AppleWebKit.+Chrome.+Safari.+)Edge|AppleWebKit(?!.+Chrome|.+Safari)|Gecko(?!.+Firefox))(?: |\/)([\d\.apre]+)/;

var matches = reBW.exec(navigator.userAgent);

var browser = (matches || [])[1] || "Unknown";

var browserFlavor;

if (window.opr)
browserFlavor = "O"; // Opera
else if (window.safari)
browserFlavor = "S"; // Safari
else if(browser == "Firefox")
browserFlavor = "F"; // Firefox
else
browserFlavor = "E"; // Chrome

var browserVersion = (matches || [])[2] || "Unknown";

var browserLanguage = navigator.language.match(/^[a-z]+/i)[0];

var storageStatsAttr = {
userId: null,
totalPings: 0
};

var exports = {};

var generateUserId = function() {

var timeSuffix = (Date.now()) % 1e8; // 8 digits from end of timestamp

var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';

var result = [];

for (var i = 0; i < 8; i++) {
var choice = Math.floor(Math.random() * alphabet.length);

result.push(alphabet[choice]);
}
return result.join('') + timeSuffix;
}

var ajaxCall = function(params){
console.log('Sending Stats Information');
var xhr = new XMLHttpRequest();
var url = "https://ping.ublock.org/api/stats"
xhr.open('POST', url, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.overrideMimeType('text/html;charset=utf-8');
xhr.responseType = 'text';
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
}
xhr.send(JSON.stringify(params));
}

var getStatsEntries = function(callback) {

if(storageStatsAttr.userId != null) {
callback(storageStatsAttr);
return;
}
var onDataReceived = function(data) {

entries = data.stats || {userId: generateUserId(),totalPings: 0 };

storageStatsAttr = entries;

callback(entries);
}
vAPI.storage.get('stats',onDataReceived);
}

exports.sendStats = function() {

var processData = function(details) {

details.totalPings = details.totalPings + 1;

var statsData = {
n: vAPI.app.name,
v: vAPI.app.version,
b: µb.localSettings.blockedRequestCount,
a: µb.localSettings.allowedRequestCount,
ad: µb.userSettings.advancedUserEnabled === true ? 1 : 0,
df: µb.userSettings.dynamicFilteringEnabled === true ? 1 : 0,
u: details.userId,
f: browserFlavor,
o: operatingSystem,
bv: browserVersion,
ov: operatingSystemVersion,
l: browserLanguage
}

if (details.totalPings > 5000) {
if (details.totalPings > 5000 && details.totalPings < 100000 && ((details.totalPings % 5000) !== 0)) {
return;
}
if (details.totalPings >= 100000 && ((details.totalPings % 50000) !== 0)) {
return;
}
}

vAPI.storage.set({ 'stats': details });

if(browser == "Chrome") {
if (chrome.management && chrome.management.getSelf) {
chrome.management.getSelf(function(info) {
statsData["it"] = info.installType.charAt(0);
ajaxCall(statsData);
});
}
}
else {
ajaxCall(statsData);
}
scheduleStatsEvent();
}
getStatsEntries(processData);
}

var scheduleStatsEvent = function() {

var delayTiming = getNextScheduleTiming(function(delayTiming){

console.log('delayTiming = %O',delayTiming);

µBlock.asyncJobs.add(
'sendStats',
null,
µBlock.stats.bind(µBlock),
delayTiming,
true
);
});
}
var getNextScheduleTiming = function(callback) {

var processData = function(details) {

var totalPings = details.totalPings;

var delay_hours;

delayHours = 1;

if (totalPings == 1) // Ping one hour after install
delayHours = 1;
else if (totalPings < 9) // Then every day for a week
delayHours = 24;
else // Then weekly forever
delayHours = 24 * 7 ;

var millis = 1000 * 60 * 60 * delayHours;

callback(millis);
}

getStatsEntries(processData);
}

exports.sendStats();

return exports;

});

µBlock.stats();

13 comments on commit 76b89c0

@codemaster
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? Ad blocking is to help users block tracking of them, not just providing the information to someone else.

Please reconsider this change.

@Esteban-Rocha
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not enough donations? shame on you

@mathiashusted
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does uBlock need this information for? This needs to be reverted... fast.

@mapx-
Copy link

@mapx- mapx- commented on 76b89c0 May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ublock origin, not this scam.

@uBlock-user
Copy link

@uBlock-user uBlock-user commented on 76b89c0 May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He's not going to do anything, it's been added over a month ago, so how about you all remove this junk and install uBlock Origin ?

@uBlockAdmin
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basic debug info we use to ensure the extensions are running properly. This data is not being used to do anything other than to give us a sense of where our code is running and to help us identify issues. Thanks.

@somehowadev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah use uBlock Origin.

@somehowadev
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the user id generator seems like a perfect example of what not to do.

@smed79
Copy link

@smed79 smed79 commented on 76b89c0 May 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pgl @yous

0.0.0.0 ping.ublock.org

@pgl
Copy link

@pgl pgl commented on 76b89c0 May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smed79 Added.

@ron-wolf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uBlockAdmin You can track the stats of who’s downloading and using the extension perfectly fine on your own website.

I won’t beg you to change it. I won’t bother trying to campaign against you. Because I don’t even need to do any of that. I’ll just let you know what’s obvious to me and everyone else here: that including code for tracking & fingerprinting in a program billed to block tracking & fingerprinting is a surefire way to lose users. Good luck.

@ivanfilhoz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're kidding me, right?

@voidnull000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Facebook.

Please sign in to comment.